import Vue from 'vue'
import VueRouter from 'vue-router'
import HomeView from '../views/HomeView.vue'

Vue.use(VueRouter)

const routes = [
  {
    path: '/',
    name: 'home',
    component: HomeView,
    children:[
      {
        path: '/welcome',
        name: 'welcome',
        component: () => import('../views/Welcome.vue')
      },
      {
        path: '/users',
        name: 'users',
        component: () => import('../views/Users.vue')
      },
      {
        path: '/roles',
        name: 'roles',
        component: () => import('../views/Roles.vue')
      },
      {
        path: '/rights',
        name: 'rights',
        component: () => import('../views/Rights.vue')
      },
      {
        path: '/goods',
        name: 'goods',
        component: () => import('../views/Goods.vue')
      },
      {
        path:'/categories',
        name: 'categories',
        component: () => import('../views/Categories.vue')
      },
      {
        path:'/Classif',
        name: 'Classif',
        component: () => import('../views/Classif.vue')
      },
      {
        path:'/params',
        name: 'params',
        component: () => import('../views/params.vue')
      },
      {
        path:'/orders',
        name: 'orders',
        component: () => import('../views/orders.vue')
      },
      {
        path:'/bbb',
        name: 'bbb',
        component: () => import('../views/bbb.vue'),
        children:[
          {
            path:'/kkk',
            name: 'kkk',
            component: () => import('../views/kkk.vue')
          }
        ]
      }
    ]
    // params
  },
  {
    path: '/about',
    name: 'about',
    component: () => import('../views/AboutView.vue')
  },
  {
    path: '/Login',
    name: 'Login',
    component: () => import('../views/Login.vue')
  }
]

const router = new VueRouter({
  routes
})
// 路由全局守卫
router.beforeEach((to,form,next)=>{
  if(sessionStorage.getItem('token')){
       next()
  }else{
    if(to.path === '/login'){
      next()
    }else{
      next('/login')
    }
  }
})
export default router
